package com.duran.test;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class HobbyValidator implements ConstraintValidator<IsValidHobby, String> {
    private String lisOfValidHobbies;
    @Override
    public void initialize(IsValidHobby isValidHobby) {
        this.lisOfValidHobbies = isValidHobby.listOfValidHobbies();
    }

    @Override
    public boolean isValid(String studentHobby, ConstraintValidatorContext ctx) {

        if(studentHobby == null) {

            return false;
        }

        if (studentHobby.matches(lisOfValidHobbies)) {

            return true;
        } else {

            return false;
        }
    }

}
